//
//  MusicPlayView.m
//  NuwaRobot
//
//  Created by Kendama on 2018/1/26.
//  Copyright © 2018年 Kendama. All rights reserved.
//

#import "MusicPlayView.h"
#import "DrawMarqueeView.h"
#import "NSString+Size.h"

@interface MusicPlayView()<DrawMarqueeViewDelegate>


@end

@implementation MusicPlayView

- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        UIView *superView = self;
        _titleLabel = [[UILabel alloc]init];
        [superView addSubview:_titleLabel];
        [_titleLabel setFont:fontWithSize(15)];
        [_titleLabel setTextColor:[UIColor whiteColor]];
    }
    return _titleLabel;
}
- (UIButton *)playButton
{
    if(!_playButton)
    {
        UIView *superView = self;
        _playButton = [[UIButton alloc]init];
        [superView addSubview:_playButton];
        [_playButton sizeToFit];
        [_playButton setImage:imageWithName(@"icon_play") forState:UIControlStateNormal];
        [_playButton setImage:imageWithName(@"icon_pause") forState:UIControlStateSelected];
    }
    return _playButton;
}


#pragma mark --- 懒加载
- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    CGFloat edge = px1080Width(20);
    UIButton *button = ({
        button = [[UIButton alloc] init];
        [superView addSubview:button];
        [button setTitle:@"正在播放" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [button setImage:imageWithName(@"music") forState:UIControlStateNormal];
        button.titleLabel.font = fontWithSize(13);
        [button sizeToFit];
        [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(superView.mas_centerY);
            make.left.mas_equalTo(superView.mas_left).with.offset(edge);
            make.width.mas_equalTo(80);
        }];
        button;
    });
    
    
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right).with.offset(-edge);
        make.height.mas_equalTo(superView);
        make.width.mas_equalTo(40);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(button.mas_right).with.offset(edge);
        make.right.mas_equalTo(_playButton.mas_left).with.offset(-edge);
    }];

//    self.titleLabel.text = @"邓丽君【慢慢人生路】";
    
    
//    DrawMarqueeView *drawMarqueeView  = [[DrawMarqueeView alloc] init];
////                                         WithFrame:CGRectMake(px1080Width(40)+80, 0, SCREEN_HEIGHT-px1080Width(20)*2 - 80 - 60, px1920Height(120))];
//    drawMarqueeView.speed             = 0.5f;
//    drawMarqueeView.delegate          = self;
//    drawMarqueeView.marqueeDirection  = kDrawMarqueeLeft;
//    [self addSubview:drawMarqueeView];
//    [drawMarqueeView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(superView.mas_centerY);
//        make.left.mas_equalTo(button.mas_right).with.offset(edge);
//        make.right.mas_equalTo(_playButton.mas_left).with.offset(-edge);
//        make.height.mas_equalTo(superView);
//    }];
//
//
//    UILabel *label                    = [[UILabel alloc]init];
//    NSString *string = @"123456789012345678901234567890123456789012345678901234567890";
//    CGFloat width = [string widthWithFont:[UIFont systemFontOfSize:17] constrainedToHeight:px1920Height(120)];
//    //宽度应该根据text的长度计算
//    label.frame                       = CGRectMake(0, 0, width, px1920Height(120));
////    [label sizeToFit];
//    label.text                        = string;
//    label.textColor                   = [UIColor whiteColor];
//    [drawMarqueeView addContentView:label];
//    [drawMarqueeView startAnimation];
}

@end
